<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="back-btn" @click="navigateBack">
        <text>&lsaquo;&lsaquo;</text>
      </view>
      <view class="nav-title">团购详情</view>
      <view class="nav-right"></view>
    </view>

    <!-- 团购详情内容 -->
    <view class="detail-content">
      <!-- 标题 -->
      <view class="detail-title">
        <text>{{ currentItem.title }}</text>
      </view>
      
      <!-- 组织方和发布时间 -->
      <view class="detail-meta">
        <text class="organizer">{{ currentItem.organizer }}</text>
        <text class="publish-time">{{ currentItem.publishTime }}</text>
      </view>
      
      <!-- 图片 -->
      <view class="detail-image">
        <image :src="currentItem.imageUrl" mode="aspectFill"></image>
      </view>
      
      <!-- 价格信息 -->
      <view class="price-section">
        <view class="price-info">
          <text class="current-price">¥{{ currentItem.price.toFixed(2) }}</text>
          <text class="original-price">原价: ¥{{ currentItem.originalPrice.toFixed(2) }}</text>
        </view>
      </view>
      
      <!-- 详细描述 -->
      <view class="description-section">
        <text class="description-text">{{ currentItem.description }}</text>
      </view>
      
      <!-- 其他信息 -->
      <view class="info-section">
        <view class="info-item">
          <text class="info-label">截止日期:</text>
          <text class="info-value">{{ currentItem.deadline }}</text>
        </view>
        <view class="info-item">
          <text class="info-label">咨询电话:</text>
          <text class="info-value">{{ currentItem.contactPhone }}</text>
        </view>
        <view class="info-item">
          <text class="info-label">注意事项:</text>
          <text class="info-value">暂无</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';

// 获取路由参数
const route = useRoute();

// 当前团购项目数据
const currentItem = ref({
  id: '',
  title: '加载中...',
  imageUrl: '',
  price: 0,
  originalPrice: 0,
  organizer: '',
  publishTime: '',
  deadline: '',
  contactPhone: '',
  description: ''
});

// 模拟团购数据
const groupBuyData = [
  {
    id: '1',
    title: '北京四日追花拍摄秘密-故宫',
    imageUrl: 'https://img95.699pic.com/xsj/18/vt/8o.jpg!/fh/300',
    price: 99.00,
    originalPrice: 199.00,
    organizer: '济源广播旅游团',
    publishTime: '2022/10/10 11:09',
    deadline: '2022-10-20 23:59',
    contactPhone: '0391-66666666',
    description: '为了丰富小区业主周末生活，提高业主幸福感，焦作公交集团推出《公交社区带您游焦作》的周边游活动。《梦桃源温泉专线》根据报名人数派发车辆(最少30人起发);本周日上午9点发车。约半小时车程到达梦桃源水城温泉。'
  },
  {
    id: '2',
    title: '北京四日追花拍摄秘密-故宫',
    imageUrl: 'https://img95.699pic.com/xsj/18/vt/8o.jpg!/fh/300',
    price: 99.00,
    originalPrice: 199.00,
    organizer: '济源广播旅游团',
    publishTime: '2022/10/10 11:09',
    deadline: '2022-10-20 23:59',
    contactPhone: '0391-66666666',
    description: '为了丰富小区业主周末生活，提高业主幸福感，焦作公交集团推出《公交社区带您游焦作》的周边游活动。《梦桃源温泉专线》根据报名人数派发车辆(最少30人起发);本周日上午9点发车。约半小时车程到达梦桃源水城温泉。'
  },
  {
    id: '3',
    title: '北京四日追花拍摄秘密-故宫',
    imageUrl: 'https://img95.699pic.com/xsj/18/vt/8o.jpg!/fh/300',
    price: 99.00,
    originalPrice: 199.00,
    organizer: '济源广播旅游团',
    publishTime: '2022/10/10 11:09',
    deadline: '2022-10-20 23:59',
    contactPhone: '0391-66666666',
    description: '为了丰富小区业主周末生活，提高业主幸福感，焦作公交集团推出《公交社区带您游焦作》的周边游活动。《梦桃源温泉专线》根据报名人数派发车辆(最少30人起发);本周日上午9点发车。约半小时车程到达梦桃源水城温泉。'
  }
];

// 返回上一页
const navigateBack = () => {
  uni.navigateBack();
};

// 初始化页面数据
const initData = () => {
  const id = route.query.id || '1';
  const item = groupBuyData.find(item => item.id === id) || groupBuyData[0];
  currentItem.value = item;
};

onMounted(() => {
  initData();
});
</script>

<style scoped>
.container {
  background-color: #f8f8f8;
  min-height: 100vh;
}

/* 顶部导航栏 */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  background-color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.back-btn {
  width: 40px;
  font-size: 20px;
  color: #333;
}

.nav-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.nav-right {
  width: 40px;
}

/* 详情内容样式 */
.detail-content {
  background-color: #fff;
  padding-bottom: 20px;
}

.detail-title {
  padding: 15px;
  font-size: 18px;
  font-weight: bold;
  color: #333;
  line-height: 1.5;
}

.detail-meta {
  padding: 0 15px 15px;
  display: flex;
  justify-content: space-between;
  color: #666;
  font-size: 14px;
  border-bottom: 1px solid #f0f0f0;
}

.detail-image {
  width: 100%;
  overflow: hidden;
}

.detail-image image {
  width: 100%;
  height: 250px;
}

/* 价格样式 */
.price-section {
  padding: 15px;
  border-bottom: 10px solid #f5f5f5;
}

.price-info {
  display: flex;
  align-items: baseline;
}

.current-price {
  font-size: 24px;
  font-weight: bold;
  color: #ff6b6b;
  margin-right: 10px;
}

.original-price {
  font-size: 14px;
  color: #999;
  text-decoration: line-through;
}

/* 描述样式 */
.description-section {
  padding: 15px;
  border-bottom: 10px solid #f5f5f5;
}

.description-text {
  font-size: 15px;
  color: #333;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* 信息样式 */
.info-section {
  padding: 15px;
}

.info-item {
  display: flex;
  margin-bottom: 12px;
}

.info-label {
  width: 80px;
  font-size: 15px;
  color: #666;
}

.info-value {
  flex: 1;
  font-size: 15px;
  color: #333;
}

/* 响应式设计 */
@media (max-width: 375px) {
  .detail-image image {
    height: 200px;
  }
  
  .detail-title {
    font-size: 16px;
  }
}

@media (min-width: 414px) {
  .detail-image image {
    height: 300px;
  }
}
</style>